package com.itheima.mall.service.pms;

import cn.hutool.core.convert.Convert;
import com.itheima.mall.api.pms.ProductAttributeServiceApi;
import com.itheima.mall.dto.ProductAttributeDto;
import com.itheima.mall.pojo.pms.ProductAttribute;
import com.itheima.mall.pojo.pms.ProductAttributeCategory;
import com.itheima.mall.vo.AttrInfoVo;
import com.itheima.mall.vo.PageResult;
import com.itheima.mall.vo.ProductAttributeCategoryVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
public class ProductAttributeService {
    @DubboReference
    private ProductAttributeServiceApi productAttributeServiceApi;

    /**
     * 添加商品属性分类
     * @param name
     */
    public Boolean categoryCreate(String name) {
        Boolean aBoolean = productAttributeServiceApi.categoryCreate(name);
        return aBoolean;
    }

    /**
     * 删除单个商品属性分类
     * @param id
     */
    public Boolean categoryDelete(Integer id) {
        Long categoryId = Convert.toLong(id);
        return productAttributeServiceApi.categoryDelete(categoryId);
    }

    /**
     * 分页获取所有商品属性分类
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageResult categoryList(Integer pageNum, Integer pageSize) {
       PageResult result =  productAttributeServiceApi.categoryList(pageNum,pageSize);
       return result;
    }

    /**
     *获取所有商品属性分类及其下属性
     * @return
     */
    public List<ProductAttributeCategoryVo> categoryListWithAttr() {
        List<ProductAttributeCategoryVo> list = productAttributeServiceApi.categoryListWithAttr();
        return list;
    }

    /**
     * 修改商品属性分类
     * @param id
     * @param name
     */
    public void categoryUpdate(Integer id, String name) {
        Long categoryId = Convert.toLong(id);
        productAttributeServiceApi.categoryUpdate(categoryId,name);
    }

    /**
     * 获取单个商品属性分类信息
     * @param id
     * @return
     */
    public ProductAttributeCategory selectCategory(Integer id) {
        Long categoryId = Convert.toLong(id);
        return productAttributeServiceApi.selectCategory(categoryId);
    }

    /**
     * 添加商品属性信息
     * @param productAttributeDto
     */
    public void creat(ProductAttributeDto productAttributeDto) {
        productAttributeServiceApi.create(productAttributeDto);
    }

    /**
     * 批量删除商品属性
     * @param ids
     */
    public void delete(Integer[] ids) {
        productAttributeServiceApi.delete(ids);
    }

    /**
     * 查询单个商品属性
     * @param id
     * @return
     */
    public ProductAttribute findById(Integer id) {
        Long productAttributeId = Convert.toLong(id);
        return productAttributeServiceApi.findById(productAttributeId);
    }

    /**
     *修改商品属性信息
     * @param id
     * @param productAttribute
     */
    public void update(Integer id, ProductAttribute productAttribute) {
        Long productAttributeId = Convert.toLong(id);
        productAttributeServiceApi.update(productAttributeId,productAttribute);
    }

    /**
     * 根据分类查询属性列表或参数列表
     * @param cid
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    public PageResult listCid(Integer cid, Integer pageNum, Integer pageSize, Integer type) {
        PageResult result = productAttributeServiceApi.listCid(cid,pageNum,pageSize,type);
        return result;
    }

    /**
     * 商品分类的id获取商品属性及属性分类
     * @param productCategoryId
     * @return
     */
    public List<AttrInfoVo> attrInfo(Integer productCategoryId) {
        Long id = Convert.toLong(productCategoryId);
        List<AttrInfoVo> list = productAttributeServiceApi.attrInfo(id);
        return list;
    }
}
